const StatusCode = require('../constant/StatusCode')

function ParameterRequired(message) {
  this.id = 'PARAM_REQUIRED'
  this.message = message || 'Missing parameter.'
  this.code = StatusCode.BAD_REQUEST
}

function ValidationError(message) {
  this.id = 'VALIDATION_ERROR'
  this.message = message || 'Unable to validate parameters.'
  this.code = StatusCode.BAD_REQUEST
}

function InvalidQuery(message) {
  this.id = 'INVALID_QUERY'
  this.message = message || 'Invalid Query.'
  this.code = StatusCode.BAD_REQUEST
}

function InvalidRequest(message) {
  this.id = 'INVALID_REQUEST'
  this.message = message || 'Invalid Request.'
  this.code = StatusCode.BAD_REQUEST
}

function DuplicatedRecord(message) {
  this.id = 'DUPLICATED_RECORD'
  this.message = message || 'Duplicated Record.'
  this.code = StatusCode.BAD_REQUEST
}

function InvalidLoginEmail(message) {
  this.id = 'INVALID_LOGIN_EMAIL'
  this.message = message || 'The email you entered doesn\'t belong to an account. Please check your email and try again.'
  this.code = StatusCode.UNAUTHORISED
}

function InvalidLoginPassword(message) {
  this.id = 'INVALID_LOGIN_PASSWORD'
  this.message = message || 'Sorry, your password was incorrect. Please double-check your password.'
  this.code = StatusCode.UNAUTHORISED
}

function InvalidLoginUser(message) {
  this.id = 'INVALID_LOGIN_USER'
  this.message = message || 'Your account has been disabled. For more details, please contact us.'
  this.code = StatusCode.UNAUTHORISED
}

function AuthenticationError(message) {
  this.id = 'AUTHENTICATION_ERROR'
  this.message = message || 'Invalid Authentication.'
  this.code = StatusCode.UNAUTHORISED
}

function InvalidToken(message) {
  this.id = 'INVALID_TOKEN'
  this.message = message || 'Invalid Token.'
  this.code = StatusCode.UNAUTHORISED
}

function RevokedToken(message) {
  this.id = 'REVOKED_TOKEN'
  this.message = message || 'Revoked Token.'
  this.code = StatusCode.UNAUTHORISED
}

function ExpiredToken(message) {
  this.id = 'EXPIRED_TOKEN'
  this.message = message || 'Expired Token.'
  this.code = StatusCode.UNAUTHORISED
}

function InvalidPermission(message) {
  this.id = 'INVALID_PERMISSION'
  this.message = message || 'Invalid Permission.'
  this.code = StatusCode.INVALID_SCOPE
}

function InvalidUser(message) {
  this.id = 'INVALID_USER'
  this.message = message || 'The user is disabled.'
  this.code = StatusCode.INVALID_SCOPE
}

function NotFound(message) {
  this.id = 'NOT_FOUND'
  this.message = message || 'Not found.'
  this.code = StatusCode.NOT_FOUND
}

function InternalServerError(message) {
  this.id = 'INTERNAL_SERVER_ERROR'
  this.message = message || 'Internal server error.'
  this.code = StatusCode.INTERNAL_SERVER_ERROR
}

function DatabaseError(message) {
  this.id = 'DATABASE_ERROR'
  this.message = message || 'Database error.'
  this.code = StatusCode.INTERNAL_SERVER_ERROR
}

const ResponseError = {
  ParameterRequired,
  ValidationError,
  InvalidQuery,
  InvalidRequest,
  DuplicatedRecord,
  InvalidLoginEmail,
  InvalidLoginPassword,
  InvalidLoginUser,
  AuthenticationError,
  InvalidToken,
  RevokedToken,
  ExpiredToken,
  InvalidPermission,
  InvalidUser,
  NotFound,
  InternalServerError,
  DatabaseError,
}

module.exports = ResponseError
